package gold.digger;

import gold.utils.InputUtil;

import java.util.*;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC1222 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public List<List<Integer>> queensAttacktheKing(int[][] queens, int[] king) {
            List<List<Integer>> res = new ArrayList<List<Integer>>();
            int dx[] = {-1, 1, 0, 1, 1, -1, -1, 0};//
            int dy[] = {-1, 1, 1, 0, -1, 1, 0, -1};//  dx 与 dy 合在一起表示当前进行模拟搜寻的方向
            for (int i = 0; i < 8; i++) {// 将八个方向都进行搜索
                int x = king[0];
                int y = king[1];
                while (!(x < 0 || y < 0 || x >= 8 || y >= 8)) {// 如果坐标符合条件就进行判断
                    int flag = 0;
                    for (int j = 0; j < queens.length; j++) {// 判断该位置是否为皇后所在位置
                        if (x == queens[j][0] && y == queens[j][1]) {// 如果是则添加到答案中，同时退出接下来的搜索
                            List<Integer> list = new ArrayList<Integer>();
                            list.add(x);
                            list.add(y);
                            res.add(list);
                            flag = 1;
                            break;
                        }
                    }
                    if (flag == 1) break;
                    // 坐标进行变化
                    x = x + dx[i];
                    y = y + dy[i];
                }
            }
            // 返回最终结果
            return res;
        }
    }

    public void run() {
        int[] arr = InputUtil.toIntegerArray("[1,2,3]");
        System.out.println(new Solution().toString());
    }

    public static void main(String[] args) throws Exception {
        LC1222 an = new LC1222();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
